(function() {
	
	hfrApp.factory("HfrConfig", function ($rootScope, $translate) {
		var API_SERVER = "http://server-harforent.appspot.com/api/";//server-harforent.appspot.com
		
		return {
			ApiServiceUrl: {
		                customersUrlApi: API_SERVER + "customers", //server-harforent.appspot.com
		                blogsUrlApi : API_SERVER + "blogs",
		                topicsUrlApi: API_SERVER + "topics",
		                sitemapsUrlApi: API_SERVER + "sitemaps",
		                blogTopicsUrlApi: API_SERVER + "blog-topics",
		                selectorsUrlApi: API_SERVER + "selectors",
		                postSuccessUrlApi: API_SERVER + "post-success",
		                checkPostUrlApi: API_SERVER + "check-posts",
		                checkPreviewSelectorApi: API_SERVER + "previewSelectors",
		            },
			GooglePlus: {
				clientId: "804599464095-dtb3e4utgdhp6phccd9sj8b1gf50anv7.apps.googleusercontent.com",
			},
			displayMeta: function (name) {
				$rootScope.metaTitle = $translate.instant("meta." + name + ".title");
				$rootScope.metaDescription = $translate.instant("meta." + name + ".description");
				$rootScope.metaKeyword = $translate.instant("meta." + name + ".keywords");
				
				return this;
			}
		}
	});
	
	hfrApp.factory("HfrGlobal", function ($rootScope) {
		return {
			set: function (name, val) {
				eval("$rootScope." + name) = val;
				$window.localStorage && $window.localStorage.setItem(name, val);
				return this;
			},
			get: function (name) {
				
				if (eval("$rootScope." + name) === undefined) {
					return $window.localStorage && $window.localStorage.getItem(name);
				} else {
					return eval("$rootScope." + name);
				}
			}
		}
	});
	
	//Storage and get data
	hfrApp.factory("HfrStorage", function ($window, $rootScope) {
		return {
			set: function(name, val) {
				$window.localStorage && $window.localStorage.setItem(name, val);
				return this;
			},
			get: function(name) {
				return $window.localStorage && $window.localStorage.getItem(name);
			},
			remove: function(name) {
				$window.localStorage && $window.localStorage.removeItem(name);
				return this; 
			},
			clearAll: function() {
				$window.localStorage && $window.localStorage.clear();
				return this;
			}
		}
	});
	
	//Init 
	hfrApp.factory("HfrInit", function ($rootScope, $timeout) {
		return {
			message: function () {
				$rootScope.message = {
					success	: 	false,
					error	:	false,
					text	:	""
				};
				
				$rootScope.reload = {
					display	: false,
					text	: ""	
				};
				
				return this;
			},
			loadding: function () {
				if ($rootScope.totalPageLoading === undefined) {
					$rootScope.totalPageLoading = 1;
				} else {
					$rootScope.totalPageLoading += 1;
				}
				
				if ($rootScope.totalPageLoading >= 1) {
					$timeout(function () {
						$rootScope.showBodyContent = true;
					}, 2000);
				}
			}
		}
	});
	
	hfrApp.run(function ($rootScope, $timeout) {
		
		//Tat thong bao sau thoi gian 10s (10000)
		$rootScope.$watch('message.error', function (value) {
			if (value) {
				$timeout(function () {
					$rootScope.message.error = false;
					$rootScope.message.text = "";
				}, 10000);
			}
		});
		
		$rootScope.$watch('message.success', function (value) {
			if (value) {
				$timeout(function () {
					$rootScope.message.success = false;
					$rootScope.message.text = "";
				}, 10000);
			}
		});
	});
	
})();